{% extends "base.html" %}

{% block title %}Staff{% endblock %}

{% block content %}
{% if user.is_staff %} 
<form action='{% url staff_edit %}' method='post' name='Action'>
    {% if users.object_list %}
        {% if users.has_other_pages %}
            <div class="PageCounterNav">
                <p>
                {% if users.has_previous %}
                    <a href="?page={{ users.previous_page_number }}&amp;per_page={{ per_page }}">
                        <img src="{{ MEDIA_URL }}images/pagenav_prev.gif" alt="Previous Page" />
                    </a>
                {% else %}
                    <img src="{{ MEDIA_URL }}images/pagenav_prev_faded.gif" alt="No Previous Page" />
                {% endif %}
                Pages: ({{ users.number }} of {{ users.paginator.num_pages }})
                {% if users.has_next %}
                    <a href="?page={{ users.next_page_number }}&amp;per_page={{ per_page }}">
                        <img src="{{ MEDIA_URL }}images/pagenav_next.gif" alt="Next Page" />
                    </a>
                {% else %}
                    <img src="{{ MEDIA_URL }}images/pagenav_next_faded.gif" alt="No Next Page" />
                {% endif %}
            </div>
        {% endif %}
        <table cellspacing='0'>
            <thead>
                <tr>
                    {# TODO need to sort #}
                    <th>All</th>
                    <th>Name</th>
                    <th>Permission</th>
                </tr>
            </thead>
            <tbody>
            {% for user in users.object_list %}
                <tr class="{% cycle 'bgcolor_odd' 'bgcolor_even' %}">
                    <td class='row_check'>
                        <input type='checkbox' name="idToEdit{{ forloop.counter }}" value='{{ user.id }}' {% ifequal user.id 1 %}disabled="disabled"{% endifequal %}/>
                    </td>
                    <td class='row_username'>
                        <a href="{% url user user.id %}">{{ user.get_full_name }}</a>
                    </td>
                    
                    <td class="row_permission">
                        {% if user.is_superuser %}
                             Administrator
                        {% else %}
                             Staff
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p class='noresults'>There are no staff.</p>
    {% endif %}
    {% if user.is_superuser %}
    <div class='submit_options'>
        <input type='submit' name='Action' class='submit' value='Edit' /> 
        <input type='submit' name='Action' class='submit' value='Delete' onclick="return confirm('This will permanently delete these items, are you sure?')" /> 
        <input type='submit' name='Action' class='submit' value='Add New' /> 
    </div>
    {% else %}
    <p>Only administrators can make changes to this list</p>
    {% endif %}
</form>

{% else %}
<p>You do not have permission to view this page</p>
{% endif %}

{% endblock %}
